#include <iostream>
#include <string.h>
#include <bitset>
#include "myclass.h"
using namespace std;

void move_num(unsigned int num);
void move_gu(unsigned int num);
void move_re(unsigned int num);

int main(int argc, char const *argv[])
{
    if (argc)
    {
        argv[0] = argv[0];
    }
    char num[50] = {0};
    cout << "bro,说点啥" << endl;
    cin >> num;
    cout << "你好" << num << endl;
    cout << sizeof(num) << " " << strlen(num) << endl;
    int a = func_reload(12);
    int b = func_reload(10, 2);
    std::cout << "a:" << a << " b:" << b << std::endl;

    func_class();
    func_class_stu();
    func_class_struct();
    move_num(151);
    move_gu(151);
    move_re(151);
    std::cout << "Original num 151 (binary): " << std::bitset<8>(151) << std::endl;
    std::cout << "Reverse num 233 (binary): " << std::bitset<8>(233) << std::endl;

    func_class_people();
    func_class_function();

    return 0;
}
// 10010111 ---- 151
// 11101001 ---- 233
void move_num(unsigned int num)
{
    num = (num & 0x01) << 7 | (num & 0x2) << 5 | (num & 0x04) << 3 | (num & 0x8) << 1 | (num & 0x16) >> 1 | (num & 0x32) >> 3 | (num & 0x64) >> 5 | (num & 0x128) >> 7;
    std::cout << "num" << num << std::endl;
}

void move_gu(unsigned int num)
{
    for (int i = 0; i < 4; i++)
    {
        if (((num >> i) & 1) != (((num >> (7 - i)) & 1)))
        {
            if (((num >> i) & 1) == 1)
            {
                num = num & (255 - (1 << i));
            }
            else
            {
                num = num + (1 << i);
            }

            if (((num >> (7 - i)) & 1) == 1)
            {
                num = num & (255 - (1 << (7 - i)));
            }
            else
            {
                num = num + (1 << (7 - i));
            }
        }
    }
    std::cout << "num" << num << std::endl;
}

// 10010111 ---- 151
// 11101001 ---- 233
//  递归函数：位重排
void move_re(unsigned int num)
{
    num = (num & 0x01) << 7 | (num & ((0x01) << 1)) << 5 | (num & ((0x01) << 2)) << 3 |
          (num & ((0x01) << 3)) << 1 | (num & ((0x10) >> 0)) >> 1 | (num & ((0x10) >> 1)) >> 1 |
          (num & ((0x10) >> 2)) >> 2 | (num & ((0x10) >> 3)) >> 3;
    std::cout << "num" << bitset<8>(num) << std::endl;
    std::cout << "num" << bitset<8>((0x01) << 0) << std::endl;
    std::cout << "num" << bitset<8>((0x01) << 1) << std::endl;
    std::cout << "num" << bitset<8>((0x01) << 2) << std::endl;
    std::cout << "num" << bitset<8>((0x01) << 3) << std::endl;
}


